package com.pcbly.web.action.timesheet;

import com.pcbly.web.action.BaseAction;
import com.pcbly.web.bean.timesheet.TimesheetCommentBean;
import com.pcbly.web.business.timesheet.TimesheetCommentService;

public class TimesheetCommentAction extends BaseAction<TimesheetCommentBean> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -232732124392758795L;
	protected TimesheetCommentService timesheetService; 
	
	public void setTimesheetCommentService(TimesheetCommentService timesheetService) {
		this.timesheetService = timesheetService;
	}
	private TimesheetCommentBean timesheet;
	
	
	public TimesheetCommentBean getTimesheetComment() {
		return timesheet;
	}

	public void setTimesheetComment(TimesheetCommentBean timesheet) {
		this.timesheet = timesheet;
	}
	public String view() throws Exception {
		timesheet=timesheetService.getTimesheetCommentBeanById(getId());
		return super.view();
	}
	public String update() throws Exception {
		timesheet=timesheetService.getTimesheetCommentBeanById(getId());
		return super.update();
	}
	public String index() throws Exception {
		return super.index();
	}
	public String add() throws Exception { 
		return super.add();
	}
	public String save() throws Exception {
		if (log.isDebugEnabled()) {
			log.debug("login save..........");
			log.debug(timesheet.getId());
		}
		try{
		if (timesheet.getId() == null || "".equals(timesheet.getId())) {// new 
			timesheetService.saveTimesheetCommentBean(timesheet);
			addActionMessage(getText("entity.saved"));
		} else {// update
			timesheetService.updateTimesheetCommentBean(timesheet);
			addActionMessage(getText("entity.updated"));
		}}catch(Exception e){
			e.printStackTrace();
		}
		return super.save();
	}
	public String dwrSave(TimesheetCommentBean bean) throws Exception {
		if (log.isDebugEnabled()) {
			log.debug("login save..........");
			log.debug(bean.getId());
		}
		try{
		if (bean.getId() == null || "".equals(bean.getId())) {// new 
			timesheetService.saveTimesheetCommentBean(bean);
		} else {// update
			timesheetService.updateTimesheetCommentBean(bean);
		}}catch(Exception e){
			e.printStackTrace();
		}
		return super.dwrBaseSave(bean.getId());
	}
	public String delete() throws Exception {
		if (log.isDebugEnabled()) {
			log.debug("login delete..........");
			log.debug(getId());
		}
		if(getId().indexOf(",")>=0){
			timesheetService.removeTimesheetCommentBeanByIds(getId());
		}else{
			timesheetService.removeTimesheetCommentBeanById(getId());
		}
		return super.delete();
	}
	public String dwrDelete(String id) throws Exception {
		if (log.isDebugEnabled()) {
			log.debug("login delete..........");
			log.debug(id);
		}
		if(id.indexOf(",")>=0){
			timesheetService.removeTimesheetCommentBeanByIds(id);
		}else{
			timesheetService.removeTimesheetCommentBeanById(id);
		}
		return super.dwrBaseDelete(id);
	}
	
}